package com.gimi.cloud.bbp.common.enums;

import org.apache.commons.collections.map.LinkedMap;

import java.util.*;

/**
 * 公共的枚举类
 * @author yy
 * @date 2015年11月25日
 * @version 1.0
 */
public class CommonEnume {
	public static Map<String,Class> enumsmap;
	static{
		enumsmap=new HashMap<String,Class>();
		//初始化枚举map
		//订单来源
		enumsmap.put("ordersource", CommonEnume.OrderSource.class);
		//订单状态
		enumsmap.put("orderstatus", CommonEnume.OrderStatus.class);
		//订单支付方式
		enumsmap.put("paytype", CommonEnume.PayType.class);
		enumsmap.put("logisticsstatus", CommonEnume.LogisticsStatus.class);
		//订单发货状态
		enumsmap.put("PayStatus", CommonEnume.PayStatus.class);
	}

	public interface BaseEnum {
		public abstract String getValue() ;
	}
	/**
	 * 转换枚举为Map
	 * @param clz
	 * @return
	 */
	public static Map<String, String> ConvertEnumMap(Class clz){
		Map<String, String> keymap=new LinkedMap();
		for(Object obj:clz.getEnumConstants()){
			if(obj instanceof BaseEnum){
				BaseEnum b=(BaseEnum)obj;
				if(!keymap.containsKey(obj.toString().toUpperCase()))
				keymap.put( obj.toString().toUpperCase(),b.getValue());
			}
		}
		return keymap;
	}

	/**
	 * 根据key得到枚举列表
	 * @param key
	 * @return
	 */
	public static Map<String, String> getcodelist(String key){
		if(enumsmap!=null && enumsmap.containsKey(key.toLowerCase())){
			return ConvertEnumMap(enumsmap.get(key.toLowerCase()));
		}
		return new HashMap<String, String>();
	}
	
	public static List<Map<String, String>> getCodeList1(String key) {
		if (enumsmap != null && enumsmap.containsKey(key.toLowerCase())) {
			Map<String, String> map = ConvertEnumMap(enumsmap.get(key.toLowerCase()));

			List<Map<String, String>> array = new ArrayList<Map<String, String>>();
			Set<Map.Entry<String, String>> entryseSet = map.entrySet();
			for (Map.Entry<String, String> entry : entryseSet) {
				Map<String, String> node = new HashMap<String, String>();
				node.put("code", entry.getKey());
				node.put("value", entry.getValue());
				array.add(node);
			}
			return array;
		}
		return new ArrayList<Map<String, String>>();
	}
	
	public static List<Map<String, String>> getCodeList1(String key,String deleteKey) {
		Map<String,String> delKeysMap = new HashMap<String,String>();
		for(String delKey:deleteKey.split(",")){
			delKeysMap.put(delKey, delKey);
		}
		if (enumsmap != null && enumsmap.containsKey(key.toLowerCase())) {
			Map<String, String> map = ConvertEnumMap(enumsmap.get(key.toLowerCase()));
			List<Map<String, String>> array = new ArrayList<Map<String, String>>();
			Set<Map.Entry<String, String>> entryseSet = map.entrySet();
			for (Map.Entry<String, String> entry : entryseSet) {
				if(!delKeysMap.containsKey(entry.getKey())){
					Map<String, String> node = new HashMap<String, String>();
					node.put("code", entry.getKey());
					node.put("value", entry.getValue());
					array.add(node);
				}
			}
			return array;
		}
		return new ArrayList<Map<String, String>>();
	}
	
	public static enum OrderSource implements BaseEnum {
		app("app来源"),//app来源
		wechat("微信"),//微信
		other("其他");//其他
		private final String value;
		OrderSource(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	//订单状态(A01已提交待支付,A02支付成功待收货,A03已收货,A09取消;L01已提交审核中,L02审核成功待支付,L03审核拒绝,L04支付成功待收货,,L05已收货,L09取消
	public static enum OrderStatus implements BaseEnum {
		A01("已提交待支付"),
		A02("支付成功待收货"),
		A03("已收货"),
		A09("用户取消"),
		L01("已提交审核中"),
		L02("审核成功待支付"),
		L03("审核拒绝"),
		L04("支付成功待收货"),
		L05("已收货"),
		L09("取消"),
		D01("用户删除"),;
		private final String value;
		OrderStatus(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	
	public static enum PayStatus implements BaseEnum {
		//(pay已支付,nopay未支付)
		pay("已支付"),
		nopay("未支付"),;
		private final String value;
		PayStatus(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	//支付方式(lease租赁,stages分期付款,online在线付款,delivery货到付款) 订单类型为租赁支付方式为租赁
	public static enum PayType implements BaseEnum {
		lease("租赁"),
		stages("分期付款"),
		online("在线付款"),
		delivery("货到付款");
		private final String value;
		PayType(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	
	
	public static enum PayChannel implements BaseEnum {
		ZFB("支付宝"),
		;
		private final String value;
		PayChannel(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	
	//发货状态(yes已发货,no未发货,ing发货中)
	public static enum LogisticsStatus implements BaseEnum {
		yes("已发货"),
		no("未发货"),
		ing("发货中");
		private final String value;
		LogisticsStatus(String value){
			this.value = value;
		}
		@Override
		public String getValue() {
			return value;
		} 
	}
	
}